<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Db;
class Music extends Controller
{
	public function index()
	{
		$list = Db::name('music')->select(); 
		return view('Music/index',[
			'list' => $list,
			]);
	}

	public function add()
	{
		return view('Music/add');
	}

	public function cadd(Request $request)
	{

		$p = $request->post();
		// var_dump($p);die;
		$data = ['mname' => $p['ljname'], 'mmage' => $p['ljaddress']];
		$list = Db::table('music')->insert($data);
		if ($list > 0) {
			return $this->success('添加成功',url('index/Music/index'));
		} else {
			return $this->seeor('添加失败');
		}
	}

	public function delect($id)
	{
		$list = Db::name('music')->delete($id);
		if ($list > 0) {
			return $this->success('删除成功',url('index/Music/index'));
		} else {
			return $this->seeor('删除失败');
		}
	}

	public function shang($id)
	{	
		// var_dump($ll);die;
		// $mu = Db::name('music')->where('mid',$ll)->update(['status'=>'0']);
		$list = Db::name('music')->where('mid',$id)->update(['status'=>'1']);
		if ($list > 0) {
			return $this->success('更改成功',url('index/Music/index'));
		} else {
			return $this->seeor('更改失败');
		}
	}
	public function xia($id)
	{
		$ll = Db::name('music')->field('mid')->select();
		foreach ($ll as $key => $value) {
			$ll = $value['mid'];
			$mu = Db::name('music')->where('mid',$ll)->update(['status'=>'1']);

		}
		$list = Db::name('music')->where('mid',$id)->update(['status'=>'0']);
		if ($list > 0) {
			return $this->success('更改成功',url('index/Music/index'));
		} else {
			return $this->seeor('更改失败');
		}
	}
}